<?php

App::uses('AppRule', 'Lib');

class MaxUsersAllowed extends AppRule {

    public $arguments = array(
    	'users' => 'int'
    );
    
    /**
     * (non-PHPdoc)
     * @see AppRule::apply()
     */
    public function apply(Leave $leave, $users=0) {
        $ret = true;
        
        $data = $leave->data['Leave'];
        if ($leave->getUsersBetween($data['start'], $data['end']) > $users) {
            $ret = false;
            $this->setError("Max. users allowed exceeded. ({$users} users)");
        }
        
        return $ret;
    }

}

?>